-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Source S3: basic structure using file-based CDK #28786
Conversation
Before Merging a Connector Pull RequestWow! What a great pull request you have here! 🎉 To merge this PR, ensure the following has been done/considered for each connector added or updated:
If the checklist is complete, but the CI check is failing,
|
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ❌ |
Connector version increment check | ❌ |
QA checks | ✅ |
Code format checks | ❌ |
Connector package install | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly some clarifying questions in how some of the new constructs are being used and a few small things. Overall looks good!
prefixes = {glob.split("*")[0].rstrip("/") for glob in globs} | ||
return list(filter(lambda x: bool(x), prefixes)) | ||
prefixes = {glob.split("*")[0] for glob in globs} | ||
return set(filter(lambda x: bool(x), prefixes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we need to change this from a list to set? I looked at how get_prefixes_from_globs
used in S3 and it looks like we just check it in an if statement followed by a for each loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We loop over the prefixes and submit a request to S3 for each one. I wanted to avoid submitting another request to S3 in the event that there were duplicates.
|
||
@property | ||
@abstractmethod | ||
def file_read_mode(self) -> FileReadMode: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed file_read_mode
is only used with the parser implementation file itself. So it is not strictly necessary that it be exposed in the interface. Is the idea in making it part of the interface to be an indicator that future file parser types need to provide an implementation to this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly.
@classmethod | ||
def from_file_type(cls, file_type: str) -> "FileReadMode": | ||
text_file_types = ["csv", "jsonl"] | ||
binary_file_types = ["parquet", "avro"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this being called? I didn't see it usage in the PR or when I searched in IntelliJ. The only concern here is that these statically defined constants don't work that well if we decide to move in the direction of custom file formats per source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, that was a remnant of something that I ultimately deleted. Good catch, removed.
def documentation_url(cls) -> AnyUrl: | ||
return AnyUrl("https://docs.airbyte.com/integrations/sources/s3", scheme="https") | ||
|
||
bucket: str = Field(description="Name of the S3 bucket where the file(s) exist.", order=0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit for consistency let's have everything have a title so we dont rely on pydantics auto capitalizing
|
||
@config.setter | ||
def config(self, value: Config): | ||
assert isinstance(value, Config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a comment here with our prior conversation to why we have to check this value for type safety. At face value without context it might seem redundant.
@clnoll I feel like this is worth discussing with other reviewers in the PR because it's probably one of the more confusing aspects. Since we're trying to force a specific subclass of AbstractFileBasedSpec
(in this case S3 config) which makes sense. But it causes some type check warnings since the AbstractFileBasedStreamReader
interface is generalized. I'm not sure of a better solution either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, @brianjlai, added a comment.
To give some context to other reviewers - the basic background here is that config
information is needed by both the FileBasedSource and the StreamReader, but for different reasons; FileBasedSource needs it to configure streams, and the StreamReader needs it so that it knows how to, e.g. authenticate with the storage system.
In this PR, I'm allowing FileBasedSource to read the config from disk and parse it (like normal), and once parsed, the source sets the config on the StreamReader. However, the type of config accepted by FileBasedSource is AbstractFileBasedSpec, and it only cares about keys that are source-agnostic, whereas StreamReader cares about keys that are specific to the 3rd party that it's reading from. For example, S3 will be looking for a aws_access_token_id
key, but FileBasedSource won't itself need that.
So that leads us to this situation, where the S3 StreamReader's config
setter requires a config of type (S3) Config, but the interface config setter takes an AbstractFileBasedSpec, which doesn't have S3-specific keys. To solve this, we assert that we were given the correct Config type for our type of StreamReader.
One alternative route that I went down involved reading in the config prior to the initialization of the Source, so that it could be given to the StreamReader as an argument. Since the Source requires a StreamReader, it could get the config off of that. This is somewhat undesirable because we end up reading the config twice (because AbstractSource still reads it deep within the CDK code), and it also deviates from the pattern of letting the Source validate the config, which may have error handling behavior that we want to keep. For those two reasons I'd prefer to keep the code as-is. But I'm open to other opinions.
return self._config | ||
|
||
@config.setter | ||
def config(self, value: Config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, does mypy checks not flag this since the interface method expects AbstractFileBasedSpec
even though Config
is a subclass of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah mypy doesn't seem to mind about it.
total_n_keys = 0 | ||
|
||
try: | ||
kwargs = {"Bucket": self.config.bucket} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we expecting other kwargs? I'm not sure I see the benefit of putting Bucket
behind kwargs and passing it to _page
. It just makes it more opaque what it contains in that method.
Also related nit, if we do use kwargs, I'm used to seeing it as the last parameter in the _page function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We add a ContinuationToken
in _page
, so I moved the creation of the kwargs dict there.
for remote_file in self._page(s3, globs, kwargs, None, seen, logger): | ||
yield remote_file | ||
|
||
logger.info(f"Finished listing objects from S3. Found {total_n_keys} objects total ({len(seen)} unique objects).") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although len(seen)
would be correct for both flows, wouldn't total_n_keys
always be 1 if there are no prefixes. And for prefixes, it would always log 0 since it never changes total_n_keys
. We count total_n_keys_for_prefix
within _page()
but we only print the extra log in that method.
What count are we trying to display here and would this extra log be duplicative with the ones in _page()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops yep total_n_keys
should have been in each of the for remote_file in ...
loops. Fixed.
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ❌ |
Connector version increment check | ❌ |
QA checks | ✅ |
Code format checks | ❌ |
Connector package install | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
f7fc759
to
d6998cf
Compare
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ❌ |
Connector version increment check | ❌ |
QA checks | ✅ |
Code format checks | ❌ |
Connector package install | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ❌ |
Connector version increment check | ❌ |
QA checks | ✅ |
Code format checks | ❌ |
Connector package install | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
a32b9d2
to
391a948
Compare
391a948
to
066e413
Compare
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ✅ |
Connector version increment check | ✅ |
QA checks | ✅ |
Code format checks | ❌ |
Connector package install | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
066e413
to
b7fc705
Compare
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ✅ |
Connector version increment check | ✅ |
QA checks | ✅ |
Code format checks | ❌ |
Connector package install | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
b7fc705
to
15e9d16
Compare
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ✅ |
Connector version increment check | ✅ |
QA checks | ✅ |
Code format checks | ❌ |
Connector package install | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
15e9d16
to
db7be2c
Compare
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ✅ |
Connector version increment check | ✅ |
QA checks | ✅ |
Code format checks | ✅ |
Connector package install | ✅ |
Build source-s3 docker image for platform linux/x86_64 | ✅ |
Unit tests | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
FYI I split out the file-based CDK portion of this here: #28862 |
db7be2c
to
b05fd4a
Compare
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ✅ |
Connector version increment check | ✅ |
QA checks | ✅ |
Code format checks | ✅ |
Connector package install | ✅ |
Build source-s3 docker image for platform linux/x86_64 | ✅ |
Unit tests | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
if __name__ == "__main__": | ||
args = sys.argv[1:] | ||
catalog_path = AirbyteEntrypoint.extract_catalog(args) | ||
source = FileBasedSource(SourceS3StreamReader(), Config, catalog_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to stand up the method stubs for the S3FileSource
instead of using FileBasedSource
in this PR to help if the next set of PRs easier so there aren't conflicts modifying that central class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do, but I'm not anticipating that we'll need new methods on FileBasedSource
so wasn't planning to create a separate S3FileSource
(most of the customization occurs in the objects that are passed into FileBasedSource
). Does that make sense to you or does it feel like there should be a dedicated S3FileSource
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I was sketching out the work for the S3 legacy config transformer to the new config. A lot of the config validation against the spec is done automatically in the entrypoint. So the potentially easiest way to transform legacy manifests before we perform the validation is to have an S3FileSource override BaseConnector.read_config()
.
I'm still toying with ideas about how to do it best, but so far that was the simplest way to avoid having to manage multiple specs and versions of the config. But if you don't think your work will require it, then we won't conflict anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah what I'm doing now won't require it, so I think I'll let you make that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class FileReadMode(Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to be released before the airbyte-integrations as it will not be available for the source. Consequence: if someone needs to release source-s3, the tests will fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was actually moved, in a separate PR, so I've deleted it. This PR now just consists of the S3 connector changes.
"endpoint_url": config.endpoint, | ||
"use_ssl": True, | ||
"verify": True, | ||
"config": ClientConfig(s3={"addressing_style": "auto"}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm probably missing something: why do we set client_kv_args = {"config": client_config}
if we update client_kv_args["config"]
right after with ClientConfig(s3={"addressing_style": "auto"})
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, this is awkward (a remnant of copy/pasting & an incomplete refactor). Cleaned it up.
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ✅ |
Connector version increment check | ✅ |
QA checks | ❌ |
Code format checks | ✅ |
Connector package install | ✅ |
Build source-s3 docker image for platform linux/x86_64 | ✅ |
Unit tests | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ✅ |
Connector version increment check | ✅ |
QA checks | ❌ |
Code format checks | ✅ |
Connector package install | ✅ |
Build source-s3 docker image for platform linux/x86_64 | ✅ |
Unit tests | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
7c52e0e
to
1926f1a
Compare
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ✅ |
Connector version increment check | ✅ |
QA checks | ❌ |
Code format checks | ✅ |
Connector package install | ✅ |
Build source-s3 docker image for platform linux/x86_64 | ✅ |
Unit tests | ❌ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
1926f1a
to
56d8083
Compare
source-s3 test report (commit
|
Step | Result |
---|---|
Validate airbyte-integrations/connectors/source-s3/metadata.yaml | ✅ |
Connector version semver check | ✅ |
Connector version increment check | ✅ |
QA checks | ✅ |
Code format checks | ✅ |
Connector package install | ✅ |
Build source-s3 docker image for platform linux/x86_64 | ✅ |
Unit tests | ✅ |
Integration tests | ✅ |
Acceptance tests | ✅ |
Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command
airbyte-ci connectors --name=source-s3 test
/test connector=source-s3
|
/legacy-test connector=source-s3 |
What
Adds the basic structure for using the file-based CDK for syncing data from S3:
AbstractFileBasedStreamReader
This includes a few changes to the file-based CDK.
file_type
attribute onRemoteFile
because we don't actually know the type of theRemoteFile
when we create it. We could theoretically guess based on the stream config, but there's no need to.AbstractFileBasedStreamReader
'sopen_file
method now takes in amode
argument. This is passed in by the parser that's callingopen_file
, which knows its associated file read mode.The S3 integration tests will be updated in a separate phase, which will verify that both the old and new config work.
Recommended reading order